package org.f0rb.demo.model.user;

import org.springframework.context.ApplicationContext;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.web.context.WebApplicationContext;

/**
 * Class org.f0rb.demo.model.user description goes here.
 *
 * @author Administrator
 * @version 1.0.0 11-9-28
 */
public class Struts2SpringTestCase extends Struts2TestCase {

    private static final String DEFAULT_CONTEXT_LOCATION = "classpath*:applicationContext.xml";
    protected static ApplicationContext applicationContext;

    protected void beforeInitDispatcher() {
        // only load beans from spring once
        if (applicationContext == null) {
            GenericXmlContextLoader xmlContextLoader = new GenericXmlContextLoader();
            try {
                applicationContext = xmlContextLoader.loadContext(getContextLocations());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
    }

    protected String[] getContextLocations() {
        return new String[] {DEFAULT_CONTEXT_LOCATION};
    }
}
